@extends('admin.layout.global')

@section('css-plugins')
    <link href="{{ asset('style/plugins/bootstrap-switch/css/bootstrap3/bootstrap-switch.min.css') }}" rel="stylesheet">
    <link href="{{ asset('style/plugins/chosen_v1.2.0/chosen.min.css') }}" rel="stylesheet">
    <link href="{{ asset('style/plugins/multi-select/css/multi-select.css') }}" rel="stylesheet" type="text/css" />
@endsection

@section('css')
    <link href="{{ asset('style/admin/css/custom.css') }}" rel="stylesheet">
    <style>
        .ms-container .ms-optgroup-label{
            color: #f00;
        }
    </style>
@endsection

@section('js-plugins')
    <script src="{{ asset('style/plugins/bootstrap-switch/js/bootstrap-switch.min.js') }}"></script>
    <script src="{{ asset('style/plugins/chosen_v1.2.0/chosen.jquery.min.js') }}"></script>
    <script src="{{ asset('style/plugins/multi-select/js/jquery.multi-select.js') }}" type="text/javascript"></script>
    <script src="{{ asset('style/plugins/quicksearch/jquery.quicksearch.js') }}" type="text/javascript"></script>
@endsection

@section('js')
    <script src="{{ asset('style/admin/js/pages/blankon.form.element.js') }}"></script>
    <script>
        $(function(){
            $("[type='checkbox']").bootstrapSwitch();
        });
    </script>
    <script>
        $('#custom-headers').multiSelect({
            selectableHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='搜索'>",
            selectionHeader: "<input type='text' class='search-input form-control' autocomplete='off' placeholder='搜索'>",
            afterInit: function(ms){
                var that = this,
                    $selectableSearch = that.$selectableUl.prev(),
                    $selectionSearch = that.$selectionUl.prev(),
                    selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)',
                    selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected';

                that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
                    .on('keydown', function(e){
                        if (e.which === 40){
                            that.$selectableUl.focus();
                            return false;
                        }
                    });

                that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
                    .on('keydown', function(e){
                        if (e.which == 40){
                            that.$selectionUl.focus();
                            return false;
                        }
                    });
            },
            afterSelect: function(){
                this.qs1.cache();
                this.qs2.cache();
            },
            afterDeselect: function(){
                this.qs1.cache();
                this.qs2.cache();
            }
        });
    </script>
@endsection

@section('content')
    <div class="body-content animated fadeIn">
        <div class="row">
            <div class="col-md-4">
                <div class="panel rounded shadow" id="leftMove">
                    <div class="panel-heading">
                        <div class="pull-left">
                            <h3 class="panel-title">{{ last($HMENU)->name }}</h3>
                        </div><!-- /.pull-left -->
                        <div class="pull-right">
                        </div><!-- /.pull-right -->
                        <div class="clearfix"></div>
                    </div><!-- /.panel-heading -->
                    <div class="panel-body">
                        <form method="post" onkeydown="if(event.keyCode==13)return false;">
                            <div class="form-body">
                                {!! csrf_field() !!}
                                <div class="form-group">
                                    <label class="control-label">店铺选择<span class="asterisk">*</span></label>
                                    <div class="input-group col-xs-6">
                                        <select data-placeholder="请选择店铺" name="storeID" class="chosen-select mb-15" tabindex="2">
                                            <option value=""></option>
                                            @foreach($store as $v)
                                                <option value="{{ $v->id }}" @if(old('storeID') && old('storeID') == $v->id) selected @endif>{{ $v->name }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    {!! getErrorMsg($errors, 'storeID') !!}
                                </div>
                                <div class="form-group">
                                    <label class="control-label">添加商品<span class="asterisk">*</span></label>
                                    <div class="input-group col-xs-6">
                                        <select id='custom-headers' class="form-control" multiple='multiple' name="goodsID[]">
                                            @foreach($goodsClassify as $g)
                                                <optgroup label='{{ $g->name }}'>
                                                    @foreach($goods as $v)
                                                        @if($v->classifyID == $g->id)
                                                        <option value="{{ $v->id.'-'.$v->price }}" @if(old('goodsID') && in_array($v->id.'-'.$v->price, old('goodsID'))) selected @endif>{{ $v->title }}  [{{ $v->price }}円]</option>
                                                        @endif
                                                    @endforeach
                                                </optgroup>
                                            @endforeach
                                        </select>
                                    </div>
                                    {!! getErrorMsg($errors, 'goodsID') !!}
                                </div>
                                <div class="form-group">
                                    <label class="control-label">数量<span class="asterisk">*</span></label>
                                    <input placeholder="" name="number" value="{{ old('number') }}" class="form-control" type="text">
                                    {!! getErrorMsg($errors, 'number') !!}
                                </div>
                                <div class="form-group">
                                    <label>是否上架</label><br>
                                    <input type="checkbox" name="display" checked-false data-size="small" data-on-text="上架" data-off-text="不上架" data-label-width="0" data-on-color="success" data-off-color="danger">
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <a href="{{ action('Admin\Shop\StoreGoodsController@getIndex') }}" class="btn btn-warning btn-sm btn-block"><i class="fa fa-reply"></i> <span class="bold">{{ getLang('Tips', 'rollBack') }}</span></a>
                                    </div>
                                    <div class="col-md-6">
                                        <button class="btn btn-primary btn-sm btn-block" type="submit"><i class="fa fa-check"></i>&nbsp;{{ getLang('Tips', 'submit') }}</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div><!-- /.panel-body -->
                </div><!-- /.panel -->
            </div>
        </div><!-- /.row -->
    </div>
@endsection